package com.joker.microstoremanager.repository;

import com.joker.microstoremanager.model.Goods;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface GoodsRepository extends JpaRepository<Goods,Long> {
    @Query(value = "select g from GoodsTagRelation r,Goods g where r.goods.id=g.id and r.tag.id=?1")
    Page<Goods> findByTags(Long tagName, Pageable pageable);

    @Query(value = "select g from Goods g join g.brand b where g.shop.id=?1 order by b.englishName,g.id")
    Page<Goods> findByShop(Long shopId, Pageable request);

    @Query(value = "select g from Goods g where g.shop.id=?1")
    List<Goods> findByShopId(Long id);

    Goods findBySerialNoAndShopId(String serialNo,Long shopId);
}
